package com.example.yuejianapp14.Activity.Model;

import com.example.yuejianapp14.Activity.JavaBean.Enter;
import com.example.yuejianapp14.Activity.JavaBean.Success;
import com.example.yuejianapp14.Activity.Listener.EnterListener;
import com.example.yuejianapp14.Activity.Listener.ListListener;
import com.example.yuejianapp14.Activity.Servics.EnterService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 张森 on 2017/10/31.
 */

public class EnterModel {
    private Retrofit retrofit;
    private String BASEURL = "http://10.0.2.2/YueJian/index.php/Api/Enter/";

    public EnterModel() {
        retrofit = new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void enter(String euid,String etype , String etypeid ,final ListListener<Success> listener){
        EnterService enterService=retrofit.create(EnterService.class);
        Call<Success> call=enterService.enterdata( euid,etype,etypeid);
        call.enqueue(new Callback<Success>() {
            @Override
            public void onResponse(Call<Success> call, Response<Success> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");
            }
            @Override
            public void onFailure(Call<Success> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
    public void getEnteredList(String uid, final EnterListener listener){
        EnterService enterServiceer=retrofit.create(EnterService.class);
        Call<List<Enter>> call=enterServiceer.getEnteredList(uid);
        call.enqueue(new Callback<List<Enter>>() {
            @Override
            public void onResponse(Call<List<Enter>> call, Response<List<Enter>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");
            }
            @Override
            public void onFailure(Call<List<Enter>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }

}
